/* *********************************************
as.tweenMan
************************************************

Description:	tween manager

Creation date:	Oct 24 2008
Created by:	Kirby Szeto (K0 Studios)
Modified:	-
Notes:	-

***********************************************/

import mx.transitions.Tween;

class as.tweenMan {
	// class definition
	
	private static var tM:tweenMan;
	
// 	static public var ref:MovieClip;
	
	static public var d:Object; // for tracking delayed tweens
	
	static public var g:Number; // GUID
	
	public function tweenMan () {
		d = new Object();
		g = 0;
		_global.tween_fn = t_fn; // allow backwards compatibility.
	}
	
	static public function getInstance():tweenMan {
		if (tM == null){
			tM = new tweenMan();
		}
		
		return tM;
	}
	static public var getTweenMan = getInstance; // backwards compatibility.
	
	public function t_fn(c,p,t,u,m,o,e){
		// CLIP, PROPERTIES, TARGETS, DURATION, MOTION, ONCOMPLETE, DELAY
		
		if (p[0]==undefined) { // throw it in an array if it isn't already in one.
			p = [p];
			t = [t];
		}
		
		if (e!=undefined){
			var i = g++; 
			d[ i ] = [ setInterval(tM,"dt_fn",e*1000,i), c,p,t,u,m,o ];
		} else {
			if (m==undefined) m = mx.transitions.easing.Strong.easeOut;
			
			for (var i=0;i<p.length;i++){
				c[p[i]+"_tween"] = new Tween(c, p[i], m, c[p[i]], t[i], u, true);
			}
			
			if (o!=undefined){ // only gets applied to first property
				c[p[0]+"_tween"].onMotionFinished = o;
			} else {
				c[p[0]+"_tween"].onMotionFinished = null;
			}
		}
	}
	
	public function dt_fn(id){		
		var a = d[id];

		clearInterval( a[0] );
		t_fn(a[1],a[2],a[3],a[4],a[5],a[6]);
	}
	
	public function killTween(c){
		for (var e in d){
			if (d[e][1]==c){
				clearInterval(d[e][0]);
			}
		}
	}
}